package server.implementation;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.ws.rs.POST;
import javax.xml.ws.BindingType;

import model.Author;
import model.Building;
import model.Calendar;
import model.CalendarList;
import model.Department;
import model.Direction;
import model.Group;
import model.LectureRoom;
import model.Reservation;
import model.Teacher;

import dao.Linker;

import server.interfaces.TimeTable;

@WebService(endpointInterface = "server.interfaces.TimeTable", serviceName = "TimeTable")
@SOAPBinding(style = Style.DOCUMENT)
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
public class TimeTableImpl implements TimeTable
{
	@POST
	public List<Author> getAuthors()
	{
		List<model.Author> authors = new ArrayList<model.Author>();
		authors.add(new model.Author("Kamil Buś"));
		authors.add(new model.Author("Daniel Kur"));
		authors.add(new model.Author("Artur Gertych"));
		authors.add(new model.Author("Piotr Broniszewski"));
		return authors; 
	}
	
	@POST
	public boolean getState()
	{
		return Linker.isMakeUpdate();
	}
	
	@POST
	public String getLastUpdate()
	{
		return Linker.getUpdateDate();
	}

	@POST
	public List<Department> getDepartments()
	{
		ArrayList<Department> array = new ArrayList<Department>();
		Iterator<Department> depts = Linker.mainDataAccessObject.getDepartments().values().iterator();
		while(depts.hasNext())
			array.add(depts.next());
		return array;
	}

	@POST
	public Department getDepartmentWithTeachers(String id)
	{
		return Linker.mainDataAccessObject.getDepartmentsWithTeachers().get(id);
	}

	@POST
	public Teacher getTeacherTimetable(String id)
	{
		return Linker.mainDataAccessObject.getTeachersTimetable().get(id);
	}

	@POST
	public Reservation getTeacherReservations(String id)
	{
		return Linker.mainDataAccessObject.getTeachersReservations().get(id);
	}

	@POST
	public List<Department> getDepartmentsWithDirections()
	{
		ArrayList<Department> array = new ArrayList<Department>();
		Iterator<Department> depts = Linker.mainDataAccessObject.getDepartmentsWithDirections().values().iterator();
		while(depts.hasNext())
			array.add(depts.next());
		return array;
	}

	@POST
	public Direction getDirectionWithGroups(String id)
	{
		return Linker.mainDataAccessObject.getDirectionsWithGroups().get(id);
	}

	@POST
	public Group getGroupTimetable(String id)
	{
		return Linker.mainDataAccessObject.getGroupsTimetable().get(id);
	}

	@POST
	public List<Building> getBuildings()
	{
		ArrayList<Building> array = new ArrayList<Building>();
		Iterator<Building> buil = Linker.mainDataAccessObject.getBuildings().values().iterator();
		while(buil.hasNext())
			array.add(buil.next());
		return array;
	}

	@POST
	public Building getBuildingWithLectureRooms(String id)
	{
		return Linker.mainDataAccessObject.getBuildingsWithLectureRooms().get(id);
	}

	@POST
	public LectureRoom getLectureRoomTimetable(String id)
	{
		return Linker.mainDataAccessObject.getLectureRoomsTimetable().get(id);
	}

	@POST
	public Reservation getLectureRoomReservations(String id)
	{
		return Linker.mainDataAccessObject.getLectureRoomsReservations().get(id);
	}

	@POST
	public List<CalendarList> getCalendarList()
	{
		ArrayList<CalendarList> array = new ArrayList<CalendarList>();
		Iterator<CalendarList> cale = Linker.mainDataAccessObject.getCalendarList().values().iterator();
		while(cale.hasNext())
			array.add(cale.next());
		return array;
	}

	@POST
	public Calendar getCalendar(String id)
	{
		return Linker.mainDataAccessObject.getCalendars().get(id);
	}
}
